/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iwords.service.object;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;

/**
 *
 * @author huangbaichuan
 */
@Entity
@Table(name = "syslib")
public class SysLibEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long libid;
    private Long pid;
    private Integer sortnum;
    private Integer liblevel;
    private String libname;
    private Integer quantity;
    private String description;
    @Temporal(javax.persistence.TemporalType.TIME)
    private Date createtime;
	@Temporal(javax.persistence.TemporalType.TIME)
	private Date updatetime;
	@Transient
	private boolean isFree = true;
	@Transient
	private int studyCode = 0; // 0表示未学习,1表示学习中,2表示学习完成
	@Transient
	private long percent; //学习占比
	@Transient
	private long downNum;
	@Transient
	private long surplus;

	
	/**
	 * @return the downNum
	 */
	public long getDownNum() {
		return downNum;
	}

	/**
	 * @param downNum the downNum to set 
	 */
	public void setDownNum(long downNum) {
		this.downNum = downNum;
	}

	public Date getCreatetime() {
		return createtime;
    }

    /**
	 * @return the liblevel
	 */
	public Integer getLiblevel() {
		return liblevel;
	}

	/**
	 * @return the surplus
	 */
	public long getSurplus() {
		return surplus;
	}

	/**
	 * @param surplus the surplus to set 
	 */
	public void setSurplus(long surplus) {
		this.surplus = surplus;
	}

	/**
	 * @param liblevel the liblevel to set
	 */
	public void setLiblevel(Integer liblevel) {
		this.liblevel = liblevel;
	}

	public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
	 * @return the studyCode
	 */
	public int getStudyCode() {
		return studyCode;
	}

	/**
	 * @param studyCode
	 *            the studyCode to set
	 */
	public void setStudyCode(int studyCode) {
		this.studyCode = studyCode;
	}

	/**
	 * @return the isFree
	 */
	public boolean getIsFree() {
		return isFree;
	}

	/**
	 * @param isFree the isFree to set 
	 */
	public void setFree(boolean isFree) {
		this.isFree = isFree;
	}

	public String getLibname() {
        return libname;
    }

    public void setLibname(String libname) {
        this.libname = libname;
    }

    public Long getPid() {
        return pid;
    }

    public void setPid(Long pid) {
        this.pid = pid;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Integer getSortnum() {
        return sortnum;
    }

    public void setSortnum(Integer sortnum) {
        this.sortnum = sortnum;
    }
 

  

    public Date getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(Date updatetime) {
        this.updatetime = updatetime;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (libid != null ? libid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SysLibEntity)) {
            return false;
        }
        SysLibEntity other = (SysLibEntity) object;
        if ((this.libid == null && other.libid != null) || (this.libid != null && !this.libid.equals(other.libid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.iwords.service.object.SysLibEntity[id=" + libid + "]";
    }

    /**
	 * @return the libid
	 */
	public Long getLibid() {
		return libid;
	}

	/**
	 * @param libid
	 *            the libid to set
	 */
	public void setLibid(Long libid) {
		this.libid = libid;
	}

	public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.iwords_iwords-service_jar_1.0-SNAPSHOTPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

	/**
	 * @return the percent
	 */
	public long getPercent() {
		return percent;
	}

	/**
	 * @param percent the percent to set 
	 */
	public void setPercent(long percent) {
		this.percent = percent;
	}
	
}
